package com.infodms.dms.actions.claim.dealerClaimMng;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.actions.claim.application.ClaimManualAuditing;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.bean.ClaimListBean;
import com.infodms.dms.bean.LabourPartBean;
import com.infodms.dms.bean.TtAsWrApplicationExtBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.Utility;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.dao.claim.application.ClaimManualAuditingDao;
import com.infodms.dms.dao.claim.dealerClaimMng.ClaimBillMaintainDAO;
import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.FsFileuploadPO;
import com.infodms.dms.po.TcCodePO;
import com.infodms.dms.po.TmBusinessChngCodePO;
import com.infodms.dms.po.TrBalanceClaimPO;
import com.infodms.dms.po.TtAsRoAddItemPO;
import com.infodms.dms.po.TtAsRoLabourPO;
import com.infodms.dms.po.TtAsRoRepairPartPO;
import com.infodms.dms.po.TtAsWrAppauthitemPO;
import com.infodms.dms.po.TtAsWrApplicationBackupPO;
import com.infodms.dms.po.TtAsWrApplicationExtPO;
import com.infodms.dms.po.TtAsWrApplicationPO;
import com.infodms.dms.po.TtAsWrAuthinfoPO;
import com.infodms.dms.po.TtAsWrNetitemExtPO;
import com.infodms.dms.po.TtAsWrOtherfeePO;
import com.infodms.dms.po.TtAsWrWrauthorizationPO;
import com.infodms.dms.po.TtDealerActualSalesPO;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.csv.CsvWriterUtil;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;
/**
 * 
* @ClassName: ClaimBillTrack 
* @Description: TODO(索赔申请单跟踪) 
* @author wangchao 
* @date Jun 10, 2010 1:26:45 PM 
*
 */
public class ClaimBillTrack extends BaseDao {
	
	private Logger logger = Logger.getLogger(ClaimBillTrack.class);
	private final ClaimBillMaintainDAO dao = ClaimBillMaintainDAO.getInstance();
	private final String CLAIM_BILL_URL = "/jsp/claim/dealerClaimMng/claimBillTrack.jsp";// 主页面（查询）
	private final String CLAIM_BILL_DEL_URL = "/jsp/claim/dealerClaimMng/claimBillDeleteTrack.jsp";// 删除主页面(查询)Iverson add with 2010-11-12
	private final String CLAIM_BILL_DETAIL_URL = "/jsp/claim/dealerClaimMng/claimBillDetail.jsp";// 明细页面
	private final String CLAIM_BILL_DEL_DETAIL_URL = "/jsp/claim/dealerClaimMng/claimBillDeteleDetail.jsp";// 明细页面
	private final String CLAIM_BILL_DEL_DETAIL_URL1 = "/jsp/claim/dealerClaimMng/claimBillDeteleDetail1.jsp";// 明细页面
	private final String CLAIM_BILL_RO_NO_DETAIL_URL = "/jsp/claim/dealerClaimMng/claimBillRoNoDetail.jsp";// 维修历史页面
	private final String CLAIM_BILL_VIN_URL ="/jsp/claim/dealerClaimMng/vehiclehistorydetail.jsp";//VIN码查询
	private final String PRINT_PART_URL = "/jsp/claim/dealerClaimMng/printClaimPartLabel.jsp";//配件标签打印
	
	/**
	 * 
	 * @Title: claimBillForword
	 * @Description: TODO(索赔单主页跳转)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void claimBillForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			act.setForword(CLAIM_BILL_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * Iverson add with 2010-11-12
	 * @Title: claimBillDeleteForward
	 * @Description: TODO(索赔单删除主页面跳转)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void claimBillDeleteForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			act.setForword(CLAIM_BILL_DEL_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单删除");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 
	 * @Title: applicationQuery
	 * @Description: TODO(查询索赔单)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void applicationQuery() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);     //公司ID
		StringBuffer con = new StringBuffer();
		Map<String,String> map = new HashMap<String,String>();
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			String claimNo = request.getParamValue("CLAIM_NO");
			String roNo = request.getParamValue("RO_NO");
			String lineNo = request.getParamValue("LINE_NO");
			String claimType = request.getParamValue("CLAIM_TYPE");
			String vin = request.getParamValue("VIN");
			String roStartdate = request.getParamValue("RO_STARTDATE");
			String roEnddate = request.getParamValue("RO_ENDDATE");
			String approveDate = request.getParamValue("approve_date");//审核通过时间查询条件
			String approveDate2 = request.getParamValue("approve_date2");
			String status = request.getParamValue("STATUS");
			String deliverer = request.getParamValue("DELIVERER");//客户姓名
			String delivererPhone = request.getParamValue("DELIVERER_PHONE");//客户电话
			String yieldly = request.getParamValue("YIELDLY_TYPE");//生产基地
			map.put("dealerId", dealerId);
			map.put("claimNo", claimNo);
			map.put("roNo", roNo);
			map.put("lineNo", lineNo);
			map.put("claimType", claimType);
			map.put("vin", vin);
			map.put("roStartdate", roStartdate);
			map.put("roEnddate", roEnddate);
			map.put("status", status);
			map.put("oemCompanyId", companyId.toString());
			map.put("track", "track"); //状态跟踪查询
			map.put("isApp", "isApp");
			map.put("delivererPhone", delivererPhone);
			map.put("deliverer", deliverer);
			map.put("approveDate", approveDate);
			map.put("approveDate2",approveDate2);
			map.put("yieldly",yieldly);
			//经销商代码
			if (Utility.testString(dealerId)) {
				con.append(" AND A.DEALER_ID='"+dealerId+"' \n");
			}
			//索赔单号
			if (Utility.testString(claimNo)) {
				con.append(" AND A.CLAIM_NO LIKE '%"+claimNo+"%' \n");
			}
			//工单号
			if (Utility.testString(roNo)) {
				con.append(" AND A.RO_NO LIKE '%"+roNo+"%' \n");
			}
			//行号
			if (Utility.testString(lineNo)) {
				con.append(" AND A.LINE_NO='"+lineNo+"' \n");
			}
			//索赔类型
			if (Utility.testString(claimType)) {
				con.append(" AND A.CLAIM_TYPE='"+claimType+"' \n");
			}
			//车辆VIN码
			if (Utility.testString(vin)) {
				con.append(" AND A.VIN LIKE '%"+vin+"%' \n");
			}
			//工单开始时间
			if (Utility.testString(roStartdate)) {
				con.append(" AND A.REPORT_DATE >= to_date('"+roStartdate+"', 'yyyy-mm-dd hh24:mi:ss') \n");
			}
			//工单结束时间
			if (Utility.testString(roEnddate)) {
				con.append(" AND A.REPORT_DATE <= to_date('"+roEnddate+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss') \n");
			}
			//申请状态
			if (Utility.testString(status)) {
				con.append(" AND A.STATUS='"+status+"' \n");
			}
			PageResult<TtAsWrApplicationExtBean> ps = dao.queryDealerApplication(logonUser, map,null, 10, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * Iverson add with 2010-11-12
	 * @Title: applicationDeleteQuery
	 * @Description: TODO(查询可删除的索赔单)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void applicationDeleteQuery() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);     //公司ID
		StringBuffer con = new StringBuffer();
		Date date = new Date();
		Map<String,String> map = new HashMap<String,String>();
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			String claimNo = request.getParamValue("CLAIM_NO");
			String roNo = request.getParamValue("RO_NO");
			String lineNo = request.getParamValue("LINE_NO");
			String claimType = request.getParamValue("CLAIM_TYPE");
			String vin = request.getParamValue("VIN");
			String roStartdate = request.getParamValue("RO_STARTDATE");
			String roEnddate = request.getParamValue("RO_ENDDATE");
			String approveDate = request.getParamValue("approve_date");//审核通过时间查询条件
			String approveDate2 = request.getParamValue("approve_date2");
			String status = request.getParamValue("STATUS");
			String deliverer = request.getParamValue("DELIVERER");//客户姓名
			String delivererPhone = request.getParamValue("DELIVERER_PHONE");//客户电话
			map.put("dealerId", dealerId);
			map.put("claimNo", claimNo);
			map.put("roNo", roNo);
			map.put("lineNo", lineNo);
			map.put("claimType", claimType);
			map.put("vin", vin);
			map.put("roStartdate", roStartdate);
			map.put("roEnddate", roEnddate);
			map.put("status", status);
			map.put("oemCompanyId", companyId.toString());
			map.put("track", "track"); //状态跟踪查询
			map.put("isApp", "isApp");
			map.put("delivererPhone", delivererPhone);
			map.put("deliverer", deliverer);
			map.put("approveDate", approveDate);
			map.put("approveDate2",approveDate2);
			//经销商代码
			if (Utility.testString(dealerId)) {
				con.append(" AND A.DEALER_ID='"+dealerId+"' \n");
			}
			//索赔单号
			if (Utility.testString(claimNo)) {
				con.append(" AND A.CLAIM_NO LIKE '%"+claimNo+"%' \n");
			}
			//工单号
			if (Utility.testString(roNo)) {
				con.append(" AND A.RO_NO LIKE '%"+roNo+"%' \n");
			}
			//行号
			if (Utility.testString(lineNo)) {
				con.append(" AND A.LINE_NO='"+lineNo+"' \n");
			}
			//索赔类型
			if (Utility.testString(claimType)) {
				con.append(" AND A.CLAIM_TYPE='"+claimType+"' \n");
			}
			//车辆VIN码
			if (Utility.testString(vin)) {
				con.append(" AND A.VIN LIKE '%"+vin+"%' \n");
			}
			//工单开始时间
			if (Utility.testString(roStartdate)) {
				con.append(" AND A.REPORT_DATE >= to_date('"+roStartdate+"', 'yyyy-mm-dd hh24:mi:ss') \n");
			}
			//工单结束时间
			if (Utility.testString(roEnddate)) {
				con.append(" AND A.REPORT_DATE <= to_date('"+roEnddate+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss') \n");
			}
			//申请状态
			if (Utility.testString(status)) {
				con.append(" AND A.STATUS='"+status+"' \n");
			}
			PageResult<TtAsWrApplicationExtBean> ps = dao.queryDealerDeleteApplication(logonUser, map,null, 10, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "删除索赔单");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
   /**
    * 
    * @Title: claimBillModifyForword
    * @Description: TODO(索赔单明细页面跳转)
    * @param 设定文件
    * @return void 返回类型
    * @throws
    */
	 @SuppressWarnings("unchecked")
	public void claimBillDetailForward() {
	    ActionContext act = ActionContext.getContext();
	    AclUserBean logonUser = (AclUserBean) act.getSession().get(
	        Constant.LOGON_USER);
	    try {
	      RequestWrapper request = act.getRequest();
	      //TtAsActivityPO activity = new TtAsActivityPO();
	      
	      ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
	      String id = request.getParamValue("ID");
	      String isAudit = request.getParamValue("isAudit");//是否是索赔审核（true:是，false:索赔明细查询）
	      TtAsWrApplicationExtPO tawep = auditingDao.queryClaimOrderDetailById(id);
	      List<Map<String, Object>> customerList = dao.getVinUserName2(id);
	      Map<String,Object> customerMap = new HashMap<String, Object>();
	      if(customerList!=null && customerList.size()>0)
	        customerMap = customerList.get(0);
	      
	      //取的当前需要审核的级别
	      String authCode = tawep.getAuthCode();
	      String authLevel = "--";
	      if(authCode!=null){
	    	  TtAsWrAuthinfoPO conditionPO = new TtAsWrAuthinfoPO();
	    	  conditionPO.setApprovalLevelCode(authCode);
	    	  List<TtAsWrAuthinfoPO> authLevelList = auditingDao.select(conditionPO);
	    	  if(authLevelList!=null && authLevelList.size()>0){
	    		  TtAsWrAuthinfoPO authInfoPO = authLevelList.get(0);
	    		  authLevel = CommonUtils.checkNull(authInfoPO.getApprovalLevelName());
	    	  }
	      }
	      
	      //取得产地名称
	      String yieldly = tawep.getYieldly();
	      String yieldlyName = "";
	      if(yieldly!=null){
	        TcCodePO codePO = CommonUtils.findTcCodeDetailByCodeId(CommonUtils.parseInteger(yieldly));
	        if(codePO!=null && codePO.getCodeDesc()!=null)
	          yieldlyName = codePO.getCodeDesc();
	      }
	      tawep.setYieldlyName(yieldlyName);
	      
	      List<ClaimListBean> partls = dao.queryPartById(id); //取配件信息
	      List<ClaimListBean> itemls = dao.queryItemById(id); //取工时
	      List<TtAsWrNetitemExtPO> otherls = dao.queryOtherByid(id);//取其他项目
	      List<FsFileuploadPO> attachLs = dao.queryAttById(id);//取得附件
	      List<TtAsWrAppauthitemPO> appAuthls = dao.queryAppAuthInfo(id);//审核授权信息
	      TtAsWrWrauthorizationPO authReason = dao.queryAuthReason(id);//需要授权原因
	      List<Map<String,Object>> listOutRepair = dao.viewOutRepair(tawep.getRoNo());//根据索赔单的工单号查询工单的外出维修信息
	      if(listOutRepair!=null&&listOutRepair.size()>0){
	    	  
	    	  act.setOutData("listOutRepair",listOutRepair.get(0));
	      }
	      String roNo = tawep.getRoNo();
	      act.setOutData("application", tawep);
	      act.setOutData("attachLs", attachLs);
	      act.setOutData("ID", id);//索赔申请单ID
	      act.setOutData("itemLs", itemls);//索赔单之工时信息
	      act.setOutData("partLs", partls);//索赔单之配件信息
	      act.setOutData("otherLs",otherls);//索赔单之其他项目信息
	      act.setOutData("appAuthls",appAuthls);//索赔单之审核信息
	      act.setOutData("authReason",authReason);//索赔单之审核原因
	      act.setOutData("isAudit", isAudit);//true:审核页面 false:明细查询页面
	      act.setOutData("customerMap", customerMap);//客户信息
	      act.setOutData("authLevel", authLevel);//需要审核的级别
	      
	      act.setForword(CLAIM_BILL_DETAIL_URL);
	    } catch (Exception e) {
	      BizException e1 = new BizException(act, e,
	          ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
	      logger.error(logonUser, e1);
	      act.setException(e1);
	    }
	 }
	 
	 /**
	    * Iverson add with 2010-11-12
	    * @Title: claimBillDetailDeleteForward
	    * @Description: TODO(删除索赔单跳转至明细页)
	    * @param 设定文件
	    * @return void 返回类型
	    * @throws
	    */
		 @SuppressWarnings("unchecked")
		public void claimBillDetailDeleteForward() {
		    ActionContext act = ActionContext.getContext();
		    AclUserBean logonUser = (AclUserBean) act.getSession().get(
		        Constant.LOGON_USER);
		    try {
		      RequestWrapper request = act.getRequest(); 
		      ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
		      String id = request.getParamValue("ID");
		      String isAudit = request.getParamValue("isAudit");//是否是索赔审核（true:是，false:索赔明细查询）
		      TtAsWrApplicationExtPO tawep = auditingDao.queryClaimOrderDetailById(id);
		      List<Map<String, Object>> customerList = dao.getVinUserName2(id);
		      Map<String,Object> customerMap = new HashMap<String, Object>();
		      if(customerList!=null && customerList.size()>0)
		        customerMap = customerList.get(0);
		      
		      //取的当前需要审核的级别
		      String authCode = tawep.getAuthCode();
		      String authLevel = "--";
		      if(authCode!=null){
		    	  TtAsWrAuthinfoPO conditionPO = new TtAsWrAuthinfoPO();
		    	  conditionPO.setApprovalLevelCode(authCode);
		    	  List<TtAsWrAuthinfoPO> authLevelList = auditingDao.select(conditionPO);
		    	  if(authLevelList!=null && authLevelList.size()>0){
		    		  TtAsWrAuthinfoPO authInfoPO = authLevelList.get(0);
		    		  authLevel = CommonUtils.checkNull(authInfoPO.getApprovalLevelName());
		    	  }
		      }
		      
		      //取得产地名称
		      String yieldly = tawep.getYieldly();
		      String yieldlyName = "";
		      if(yieldly!=null){
		        TcCodePO codePO = CommonUtils.findTcCodeDetailByCodeId(CommonUtils.parseInteger(yieldly));
		        if(codePO!=null && codePO.getCodeDesc()!=null)
		          yieldlyName = codePO.getCodeDesc();
		      }
		      tawep.setYieldlyName(yieldlyName);
		      
		      List<ClaimListBean> partls = dao.queryPartById(id); //取配件信息
		      List<ClaimListBean> itemls = dao.queryItemById(id); //取工时
		      List<TtAsWrNetitemExtPO> otherls = dao.queryOtherByid(id);//取其他项目
		      List<FsFileuploadPO> attachLs = dao.queryAttById(id);//取得附件
		      List<TtAsWrAppauthitemPO> appAuthls = dao.queryAppAuthInfo(id);//审核授权信息
		      TtAsWrWrauthorizationPO authReason = dao.queryAuthReason(id);//需要授权原因
		      List<Map<String,Object>> listOutRepair = dao.viewOutRepair(tawep.getRoNo());//根据索赔单的工单号查询工单的外出维修信息
		      if(listOutRepair!=null&&listOutRepair.size()>0){
		    	  
		    	  act.setOutData("listOutRepair",listOutRepair.get(0));
		      }
		      String roNo = tawep.getRoNo();
		      act.setOutData("application", tawep);
		      act.setOutData("attachLs", attachLs);
		      act.setOutData("ID", id);//索赔申请单ID
		      act.setOutData("itemLs", itemls);//索赔单之工时信息
		      act.setOutData("partLs", partls);//索赔单之配件信息
		      act.setOutData("otherLs",otherls);//索赔单之其他项目信息
		      act.setOutData("appAuthls",appAuthls);//索赔单之审核信息
		      act.setOutData("authReason",authReason);//索赔单之审核原因
		      act.setOutData("isAudit", isAudit);//true:审核页面 false:明细查询页面
		      act.setOutData("customerMap", customerMap);//客户信息
		      act.setOutData("authLevel", authLevel);//需要审核的级别
		      
		      /*************************根据索赔单ID得到索赔单状态和是否申请删除的标志***************************************************/
		      TtAsWrApplicationPO po = new TtAsWrApplicationPO();
		      po.setId(Long.parseLong(id));
		      List list = dao.selectApplicationById(po);
		      TtAsWrApplicationPO status = (TtAsWrApplicationPO)list.get(0);
		      String statusValue = status.getStatus().toString();
		      String appDel = status.getApplicationDel();
		      act.setOutData("statusValue", statusValue);
		      act.setOutData("appDel", appDel);
		      /**************************根据索赔单ID得到索赔单状态和是否申请删除的标志 end**************************************************/
		      act.setForword(CLAIM_BILL_DEL_DETAIL_URL);
		    } catch (Exception e) {
		      BizException e1 = new BizException(act, e,
		          ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
		      logger.error(logonUser, e1);
		      act.setException(e1);
		    }
		 }
		 
		 /**
		    * Iverson add with 2010-12-16
		    * 废弃索赔单是首先查询此索赔单已经被生成结算单没有
		    * @Title: isCount
		    */
			public void isCount() {
			    ActionContext act = ActionContext.getContext();
			    AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			    try {
			      RequestWrapper request = act.getRequest(); 
			      ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
			      String id = request.getParamValue("ID");
			      int count = auditingDao.isCount(id);
			      if(count>0){
			    	  act.setOutData("flag", "false");
			      }
			      act.setOutData("id", id);
			    } catch (Exception e) {
			      BizException e1 = new BizException(act, e,
			          ErrorCodeConstant.QUERY_FAILURE_CODE, "废弃索赔单是首先查询此索赔单是否生成结算单");
			      logger.error(logonUser, e1);
			      act.setException(e1);
			    }
			 }
		 
		 /**
		    * Iverson add with 2010-11-15
		    * @Title: claimBillDetailDeleteForward1
		    * @Description: TODO(跳转至删除索赔单明细页)
		    * @param 设定文件
		    * @return void 返回类型
		    * @throws
		    */
			 @SuppressWarnings("unchecked")
			public void claimBillDetailDeleteForward1() {
			    ActionContext act = ActionContext.getContext();
			    AclUserBean logonUser = (AclUserBean) act.getSession().get(
			        Constant.LOGON_USER);
			    try {
			      RequestWrapper request = act.getRequest(); 
			      ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
			      String id = request.getParamValue("ID");
			      String isAudit = request.getParamValue("isAudit");//是否是索赔审核（true:是，false:索赔明细查询）
			      TtAsWrApplicationExtPO tawep = auditingDao.queryClaimOrderDetailById11(id);
			      List<Map<String, Object>> customerList = dao.getVinUserName2(id);
			      Map<String,Object> customerMap = new HashMap<String, Object>();
			      if(customerList!=null && customerList.size()>0)
			        customerMap = customerList.get(0);
			      
			      //取的当前需要审核的级别
			      String authCode = tawep.getAuthCode();
			      String authLevel = "--";
			      if(authCode!=null){
			    	  TtAsWrAuthinfoPO conditionPO = new TtAsWrAuthinfoPO();
			    	  conditionPO.setApprovalLevelCode(authCode);
			    	  List<TtAsWrAuthinfoPO> authLevelList = auditingDao.select(conditionPO);
			    	  if(authLevelList!=null && authLevelList.size()>0){
			    		  TtAsWrAuthinfoPO authInfoPO = authLevelList.get(0);
			    		  authLevel = CommonUtils.checkNull(authInfoPO.getApprovalLevelName());
			    	  }
			      }
			      
			      //取得产地名称
			      String yieldly = tawep.getYieldly();
			      String yieldlyName = "";
			      if(yieldly!=null){
			        TcCodePO codePO = CommonUtils.findTcCodeDetailByCodeId(CommonUtils.parseInteger(yieldly));
			        if(codePO!=null && codePO.getCodeDesc()!=null)
			          yieldlyName = codePO.getCodeDesc();
			      }
			      tawep.setYieldlyName(yieldlyName);
			      
			      List<ClaimListBean> partls = dao.queryPartById(id); //取配件信息
			      List<ClaimListBean> itemls = dao.queryItemById(id); //取工时
			      List<TtAsWrNetitemExtPO> otherls = dao.queryOtherByid(id);//取其他项目
			      List<FsFileuploadPO> attachLs = dao.queryAttById(id);//取得附件
			      List<TtAsWrAppauthitemPO> appAuthls = dao.queryAppAuthInfo(id);//审核授权信息
			      TtAsWrWrauthorizationPO authReason = dao.queryAuthReason(id);//需要授权原因
			      List<Map<String,Object>> listOutRepair = dao.viewOutRepair(tawep.getRoNo());//根据索赔单的工单号查询工单的外出维修信息
			      if(listOutRepair!=null&&listOutRepair.size()>0){
			    	  
			    	  act.setOutData("listOutRepair",listOutRepair.get(0));
			      }
			      String roNo = tawep.getRoNo();
			      act.setOutData("application", tawep);
			      act.setOutData("attachLs", attachLs);
			      act.setOutData("ID", id);//索赔申请单ID
			      act.setOutData("itemLs", itemls);//索赔单之工时信息
			      act.setOutData("partLs", partls);//索赔单之配件信息
			      act.setOutData("otherLs",otherls);//索赔单之其他项目信息
			      act.setOutData("appAuthls",appAuthls);//索赔单之审核信息
			      act.setOutData("authReason",authReason);//索赔单之审核原因
			      act.setOutData("isAudit", isAudit);//true:审核页面 false:明细查询页面
			      act.setOutData("customerMap", customerMap);//客户信息
			      act.setOutData("authLevel", authLevel);//需要审核的级别
			      
			      /****************************************************************************/
			      /*TtAsWrApplicationPO po = new TtAsWrApplicationPO();
			      po.setId(Long.parseLong(id));
			      List list = dao.selectApplicationById(po);
			      TtAsWrApplicationPO status = (TtAsWrApplicationPO)list.get(0);
			      String statusValue = status.getStatus().toString();
			      String appDel = status.getApplicationDel();
			      act.setOutData("statusValue", statusValue);
			      act.setOutData("appDel", appDel);*/
			      /****************************************************************************/
			      
			      act.setForword(CLAIM_BILL_DEL_DETAIL_URL1);
			    } catch (Exception e) {
			      BizException e1 = new BizException(act, e,
			          ErrorCodeConstant.QUERY_FAILURE_CODE, "审核删除索赔单");
			      logger.error(logonUser, e1);
			      act.setException(e1);
			    }
			 }
	
	/**
	 * 
	 * @Title: getChngCodeStr
	 * @Description: TODO(取得故障代码，质损区域，质损类型，质损程度下拉框)
	 * @param
	 * @param type
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	public String getChngCodeStr(int type) {
		ActionContext ctx = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) ctx.getSession().get(
				Constant.LOGON_USER);
		Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);     //公司ID
		List<TmBusinessChngCodePO> seriesList = dao.queryChngCodeByType(type,companyId,null,null);
		String retStr = "[{";
		//retStr += "<option value=\'\'>-请选择-</option>";
		for (int i = 0; i < seriesList.size(); i++) {
			TmBusinessChngCodePO bean = new TmBusinessChngCodePO();
			bean = (TmBusinessChngCodePO) seriesList.get(i);
			retStr +=  ",'"+bean.getCode() + "':\'"
					+ bean.getCodeName() + "\'";
		}
		retStr += "}]";
		retStr = retStr.replaceFirst(",", "");
		return retStr;
	}
	
	/**
	 * 
	 * @Title: getOtherfeeStr
	 * @Description: TODO(取得其他费用下拉框)
	 * @param
	 * @param type
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	public String getOtherfeeStr() {
		ActionContext ctx = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) ctx.getSession().get(
				Constant.LOGON_USER);
		Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);     //公司ID
		List<TtAsWrOtherfeePO> seriesList = dao.queryOtherFee(companyId);
		String retStr = "";
		retStr += "<option value=\'\'>-请选择-</option>";
		for (int i = 0; i < seriesList.size(); i++) {
			TtAsWrOtherfeePO bean = new TtAsWrOtherfeePO();
			bean = (TtAsWrOtherfeePO) seriesList.get(i);
			retStr += "<option value=\'" + bean.getFeeId() + "\'" + "title=\'"
					+ bean.getFeeName() + "\'>" + bean.getFeeCode()
					+ "</option>";
		}
		return retStr;
	}
	
	/**
	 * 
	 * @Title: claimBillRoNoForward
	 * @Description: TODO(根据工单号查询车辆维护记录)
	 * @param
	 * @param type
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	public void claimBillRoNoForward(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try{
			String roNo = act.getRequest().getParamValue("roNo");
			List<TtAsRoAddItemPO> items = dao.queryAddItem(roNo,null) ;
			List<TtAsRoLabourPO> repairs = dao.queryRepairitem(roNo,null) ;
			List<TtAsRoRepairPartPO> parts = dao.queryRepairPart(roNo,null) ;
			act.setOutData("items", items);
			act.setOutData("repairs", repairs);
			act.setOutData("parts", parts);
			act.setForword(CLAIM_BILL_RO_NO_DETAIL_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "维修记录查询");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
		/**
	 * 
	 * @Title: claimBillForword
	 * @Description: TODO(车辆维修历史明细（索赔）)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void claimBillTrackForword() {
		ActionContext act = ActionContext.getContext();
		
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer.parseInt(request.getParamValue("curPage")): 1; // 处理当前页
			Integer pageSize = 10;
			String vin = request.getParamValue("vin");
			//List<LabourPartBean> lists= dao.queryLabourPartBean(vin);
			List<LabourPartBean> pageresults= dao.queryLabourPartBean(vin,pageSize, curPage);
			//System.out.println(lists.size()+lists.toString());
			//act.setOutData("lists",lists);
			act.setOutData("lists", pageresults);
			act.setForword(CLAIM_BILL_VIN_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,ErrorCodeConstant.QUERY_FAILURE_CODE, "车辆维修历史明细（索赔）");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
		}
	
	/**
	 * 打印索赔单配件标签
	 */
	public void printClaimPartLabel(){
		
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		
		try {
			RequestWrapper request = act.getRequest();
			String id = request.getParamValue("id");
			if(id==null)
				id = "-1";
			List<Map<String,Object>> resultList = dao.queryClaimPart(CommonUtils.parseLong(id));
			act.setOutData("claimId", id);
			act.setOutData("pf", resultList);

			//zhumingwei 2011-03-11  此方法用于区分轿车和微车
			TcCodePO codePo= new TcCodePO();
			codePo.setType(Constant.chana+"");
			TcCodePO poValue = (TcCodePO)dao.select(codePo).get(0);
			String codeId = poValue.getCodeId();
			act.setOutData("codeId", Integer.parseInt(codeId));
			//zhumingwei 2011-03-11
			act.setForword(this.PRINT_PART_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单配件标签打印");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	public void toExcel() {
		
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUserBean = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		OutputStream os = null;
		try {
			String fileName = "旧件回收标签列表.csv";
			fileName = new String(fileName.getBytes("GBK"), "ISO8859-1");
			act.getResponse().setContentType("Application/text/csv");
			act.getResponse().addHeader("Content-Disposition", "attachment;filename="
					+ fileName);
			
			List<List<Object>> list = new LinkedList<List<Object>>();
			List<Object> titleList = genHead();
			list.add(titleList);
			
			String returnId = request.getParamValue("claimId");//获取回运清单的修改主键
			
			List<Map<String, Object>> details = dao.queryClaimPart(CommonUtils.parseLong(returnId));
			
			for (Map<String, Object> detail : details) {
				list.add(genBody(detail));
			}
			os = act.getResponse().getOutputStream();
			CsvWriterUtil.writeCsv(list, os);
			os.flush();
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务车导出功能 ");
			logger.error(logonUserBean, e1);
			act.setException(e1);
		} finally {
			if (null != os) {
				try {
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	/**
	* 
	* @Title: genHead 
	* @Description: TODO(生成Excel表头) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	private List<Object> genHead() {
		List<Object> titleList = new LinkedList<Object>();
		//titleList.add("序号");
		titleList.add("三包单号");
		titleList.add("VIN码");
		titleList.add("生产厂家");
		titleList.add("车型");
		titleList.add("发动机号");
		titleList.add("行驶里程");
		titleList.add("购车日期");
		titleList.add("服务商代码");
		titleList.add("零件名称");
		titleList.add("零件编码");
		titleList.add("配套厂家");
		titleList.add("故障");
		titleList.add("客户姓名");
		titleList.add("电话");
		return titleList;
	}
	
	private List<Object> genBody(Map<String, Object> detail) {
		List<Object> dataList = new LinkedList<Object>();
		dataList.add(CommonUtils.checkNull(detail.get("CLAIM_NO")));        //三包单号
		dataList.add(CommonUtils.checkNull(detail.get("VIN")));             //VIN码
		dataList.add(CommonUtils.checkNull(detail.get("YIELDLY")));         //生产厂家
		dataList.add(CommonUtils.checkNull(detail.get("MODEL_CODE")));	    //车型
		dataList.add(CommonUtils.checkNull(detail.get("ENGINE_NO")));		//发动机号
		dataList.add(CommonUtils.checkNull(detail.get("IN_MILEAGE")));		//行驶里程
		dataList.add(CommonUtils.checkNull(detail.get("PURCHASED_DATE")));	//购车日期
		dataList.add(CommonUtils.checkNull(detail.get("DEALER_CODE")));		//服务商代码
		dataList.add(CommonUtils.checkNull(detail.get("PART_NAME")));		//零件名称
		dataList.add(CommonUtils.checkNull(detail.get("PART_CODE")));		//零件编码
		dataList.add(CommonUtils.checkNull(detail.get("DC_NAME")));			//配套厂家
		dataList.add(CommonUtils.checkNull(detail.get("REMARK")));          //故障
		dataList.add(CommonUtils.checkNull(detail.get("DELIVERER")));       //客户姓名
		dataList.add(CommonUtils.checkNull(detail.get("DELIVERER_PHONE"))); //电话
		return dataList;
	}

	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}
	
	/**********************Iverson add with 2010-11-12***************************/
	/**
	 * 删除索赔单同时添加索赔单备份表
	 */
	public void deleteApplication(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUserBean = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		String id = request.getParamValue("ID");//索赔单ID
		TtAsWrApplicationPO po = new TtAsWrApplicationPO();
		po.setId(Long.parseLong(id));
		//新增索赔申请单备份表
		int count = dao.insertApplication(Long.parseLong(id));
		if(count>0){
			//更新废弃人和时间
			TtAsWrApplicationBackupPO poBack = new TtAsWrApplicationBackupPO();
			poBack.setId(Long.parseLong(id));
			TtAsWrApplicationBackupPO poBackValue = new TtAsWrApplicationBackupPO();
			poBackValue.setUpdateBy(logonUserBean.getUserId());
			poBackValue.setUpdateDate(new Date());
			dao.update(poBack, poBackValue);
			//更新废弃人和时间 end
			//删除索赔申请表
			dao.deleteApplication(po);
			//删除关系表
			TrBalanceClaimPO trPo = new TrBalanceClaimPO();
			trPo.setClaimId(Long.parseLong(id));
			dao.deleteTrBalanceClaim(trPo);
			this.claimBillDeleteForward();//跳转至首页
		}else{}	
	}
	/**
	 * 如果是第一次申请删除,就改变索赔单状态
	 */
	public void updateApplication(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		String id = request.getParamValue("ID");//索赔单ID
		TtAsWrApplicationPO po = new TtAsWrApplicationPO();
		po.setId(Long.parseLong(id));
		//新增索赔申请单备份表
		int count = dao.updateApplication(Long.parseLong(id));
		if(count>0){
			this.claimBillDeleteForward();//跳转至首页
		}else{}
	}
	/**
	 * 删除索赔单同时添加索赔单备份表(车厂端)
	 */
	public void deleteApplication1(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		String id = request.getParamValue("ID");//索赔单ID
		TtAsWrApplicationPO po = new TtAsWrApplicationPO();
		po.setId(Long.parseLong(id));
		//新增索赔申请单备份表
		int count = dao.insertApplication(Long.parseLong(id));
		if(count>0){
			//删除索赔申请表
			dao.deleteApplication(po);
			ClaimManualAuditing c = new ClaimManualAuditing();
			c.deleteClaimManualAuditingInit();//跳转至首页
		}else{}	
	}
	/**********************Iverson add with 2010-11-12***************************/
}
